Previous Book Contents Book Index Next

Inside Macintosh: Overview /
Chapter 9 - Processes


Quitting an Application

Eventually the user will quit your application, usually by choosing Quit from the File menu (or by pressing the usual keyboard equivalent, Command-Q). At that time, you should close all windows, release any memory you still are holding, and exit your main event loop. Listing 9-4 shows the DoQuit routine called by the Venn Diagrammer application when the user chooses Quit from the File menu.

Listing 9-4 Quitting your application

PROCEDURE DoQuit;
   VAR
      myWindow:   WindowPtr;
BEGIN
   myWindow := FrontWindow;            {close all windows}
   WHILE myWindow <> NIL DO
      BEGIN
         DoUpdate(myWindow);           {force redrawing window}
         DoCloseWindow(myWindow);
         myWindow := FrontWindow;
      END;
   gDone := TRUE;                      {set flag to exit main event loop}
END;
The DoQuit procedure simply closes all windows belonging to the application and then sets the application global variable gDone to indicate that the user has finished using the application. Recall that the main event loop (Listing 4-4 on page 77) terminates when gDone is TRUE.

Note
The Process Manager automatically deallocates your application partition and closes all windows when your application terminates. As a result, the Venn Diagrammer application could simply have set gDone to TRUE in response to the Quit command. However, DoQuit illustrates how to close all windows because your version of DoCloseWindow might need to prompt the user to save any unsaved data in document windows currently on the desktop.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
9 JUL 1996